<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"+ request.getServerName() + ":" + request.getServerPort()+ path + "/";
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>修改项目</title>
<base href="<%=basePath%>" />
<%@ include file="../../cuv_include.jsp"%>
<link rel="stylesheet" type="text/css" href="css/common.css" />
<script type="text/javascript" src="js/jquery-1.7.1.js"></script>
<script type="text/javascript" src="js/common.js"></script>
<style type="text/css">
table {
	margin: 10px 10px
}

td {
	line-height: 40px;
}

label {
	font-weight: bold;
}
</style>
<script type="text/javascript">    
    $(document).ready(function(){
        var options = {dataType: 'json', beforeSubmit: beforeSubmit, success: process};
        $("#updateForm").submit(function(){
            $(this).ajaxSubmit(options);
            return false;
        });
     });
  
	  function beforeSubmit() {
		  if(isEmpty($("#name").val())){
		  		alert("项目名称不能为空！");
		  		$("#name").focus();
		  		return false;
	  		}
	  		if(!validateSize($("#name").val(),2,15)){
		  		alert("项目名称不符合规格！");
		  		$("#name").focus();
        		return false;
	  		}
	  		if(isEmpty($("#version").val())){
		  		alert("项目版本不能为空！");
		  		$("#version").focus();
		  		return false;
	  		}
	  		if(isEmpty($("#projectManager").val())){
		  		alert("项目经理不能为空！");
		  		$("#projectManager").focus();
		  		return false;
	  		}
	  		if(isEmpty($("#consumer").val())){
		  		alert("客户不能为空！");
		  		$("#consumer").focus();
		  		return false;
	  		}
	  		if(isEmpty($("#status").val())){
		  		alert("请选择状态！");
		  		$("#status").focus();
		  		return false;
	  		}
	        return true;
	  }
		
	  function getPerson()
	  {
		   	var deptNo=$("#alldept").val();
			$.ajax({
			  type:"post",
			  url:"<%=basePath%>/system/user/getUserByDeptNo.do", 
			  data:'deptNo='+deptNo,
			  timeout:20000,
			  error:function() {
			      alert('服务器错误');
			    },
		 	async:false,
			success:function(data) {
				 var m=eval(data);                 //转换 成json对象
				 $("#projectManager").empty();  //清空内容 
				 $("#projectManager").prepend("<option value='' selected='selected'>请选择</option>");   //为Select插入一个Option(第一个位置) 
				 $.each(m, function(i) {  
				    $('#projectManager').append('<option value="'+m[i].enname+'">' + m[i].cnname+ '</option>');   
			     });
				
			    }
		    });
		  }
	  function process(responseJson) {
	        if(responseJson.code == 0) {
	            $('#error_label').text("错误信息：" + responseJson.message);
	            $("#p_error").show();
	            return;
	        }
	        var qs = $("#qs").val();
	        location.href = "<%=basePath%>soft/project/list.do?" + qs;
      }  
	  
</script>
</head>
<body>
	<fieldset>
		<legend>修改项目：</legend>
		<form id="updateForm" method="post" action="soft/project/update.do">
			<input type="hidden" id="id" name="id" value="${sp.id}" />
			<p id="p_error" style="margin: 10px 10px;">
				<label id="error_label" style="color: red;"></label>
			</p>
			<table>
				<tr>
					<td><label for="name">项目名称：</label></td>
					<td>
					<input type="hidden" name="oldName" value="${sp.name }">
					<input type="text" name="name" id="name"
						value="${sp.name }" /> <font color="red">&nbsp;*&nbsp;&nbsp;</font>
						<label for="cnName">长度2～15位</label></td>
				</tr>
				<tr>
					<td><label for="name">项目版本：</label></td>
					<td><input type="text" name="version" id="version"
						value="${sp.version }" /> <font color="red">&nbsp;*&nbsp;&nbsp;</font>
						<label for="cnName">长度2～15位</label></td>
				</tr>
				 <tr>
		             <td><label for="dept">部门：</label></td>
		              <td >
		               <select id="alldept"  onChange="getPerson();">
							<c:forEach var="dept" items="${allDeptList}" varStatus="status">
								<option  value="${dept.deptNo}" <c:if test = "${dept.deptNo == projectManager.deptNo}">selected</c:if>>${dept.deptName}</option>
							</c:forEach>
				    	</select>
				    	 <font color="red">&nbsp;*&nbsp;&nbsp;</font> 
		            </td>              
		          </tr>   
		          
		          <tr>
			            <td><label for="projectManager">项目经理：</label></td>
			            <td>
			                <select id="projectManager" name="projectManager" >
								<c:forEach var="u" items="${userDeptNo}" varStatus="status">
								     <option  value="${u.enname}" <c:if test = "${u.enname == projectManager.enname}">selected</c:if>>${u.cnname}</option>
							    </c:forEach>
					    	</select>
			               <font color="red">&nbsp;*&nbsp;&nbsp;</font> 
			            </td>
		          </tr>
				<tr>
					<td><label for="name">客户：</label></td>
					<td><input type="text" name="consumer" id="consumer"
						value="${sp.consumer }" /> <font color="red">&nbsp;*&nbsp;&nbsp;</font>
					</td>
				</tr>
				<tr>
					<td><label for="status">状态：</label></td>
					<td><select name="status" id="status">
							<c:forEach items="${dictItemList}" var="dict">
								<c:choose>
									<c:when test="${sp.status == dict.value}">
										<option value="${dict.value}" selected="selected">${dict.name}</option>
									</c:when>
									<c:otherwise>
										<option value="${dict.value}">${dict.name}</option>
									</c:otherwise>
								</c:choose>
							</c:forEach>
					</select> <font color="red">&nbsp;*&nbsp;&nbsp;</font></td>
				</tr>
				<tr>
					<td valign="top"><label for="description">描述：</label></td>
					<td valign="top"><textarea name="description" id="description" cols="40" rows="3"><c:out value="${sp.description }" /></textarea>
					</td>
				</tr>
				<tr>
					<td></td>
					<td><input type="submit" id="btn_update" value="提交"style="width: 80px;" /> 
					<input type="button" id="btn_back" value="返回" onclick="history.back();" style="width: 80px;" /></td>
				</tr>
			</table>
		</form>
	</fieldset>
</body>
</html>